﻿using System.Windows.Forms;
using AMatysiak.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace AMatysiakTest.Controls
{
    [TestClass]
    public class DataGridViewBoolCellTest
    {
        [TestMethod]
        public void createColumn()
        {
            DataGridView grid = new DataGridView();
            grid.Columns.Add(new DataGridViewBoolColumn());
            Type type = grid.Columns[0].GetType();

            Assert.AreEqual(typeof(DataGridViewBoolColumn), type);
        }

        [TestMethod]
        public void createCell()
        {
            DataGridView grid = new DataGridView();
            grid.Columns.Add(new DataGridViewBoolColumn());
            grid.Rows.Add(true);
            Type type = grid.Rows[0].Cells[0].GetType();

            Assert.AreEqual(typeof(DataGridViewBoolCell), type);
        }

        [TestMethod]
        public void checkValueType()
        {
            DataGridView grid = new DataGridView();
            grid.Columns.Add(new DataGridViewBoolColumn());
            grid.Rows.Add(true);
            Type type = grid.Rows[0].Cells[0].Value.GetType();

            Assert.AreEqual(typeof(bool), type);
        }

        [TestMethod]
        public void changeCell()
        {
            DataGridView grid = new DataGridView();
            grid.Columns.Add(new DataGridViewBoolColumn());
            grid.Rows.Add(true);
            grid.Rows[0].Cells[0].Value = false;
            bool value = (bool)grid.Rows[0].Cells[0].Value;

            Assert.AreEqual(false, value);
        }

        [TestMethod]
        public void changeBoolCell()
        {
            DataGridView grid = new DataGridView();
            grid.Columns.Add(new DataGridViewBoolColumn());
            grid.Rows.Add(true);
            DataGridViewBoolCell cell = (DataGridViewBoolCell)grid.Rows[0].Cells[0];
            cell.Value = false;

            Assert.AreEqual(false, cell.Value);
        }

        [TestMethod]
        public void raiseClickEvent()
        {
            bool be = false;

            DataGridView grid = new DataGridView();
            grid.Columns.Add(new DataGridViewBoolColumn());
            grid.Rows.Add(true);
            DataGridViewBoolCell cell = (DataGridViewBoolCell)grid.Rows[0].Cells[0];
            grid.CellClick += delegate
            {
                Assert.AreEqual(false, cell.Value);
                be = true;
            };
            cell.Value = false;

            if (be)
                Assert.Fail("DataGridView should raise CellClick event.");
        }
    }
}
